import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export let routes = [
  // {
  //   path: '/404',
  //   component: () => import('@/views/404'),
  //   hidden: true
  // },
  // {
  //   path: '/',
  //   redirect: '/overview',
  //   component: Layout,
  //   children: [{
  //     path: 'overview',
  //     name: 'overview',
  //     component: () => import('@/views/overview'),
  //     meta: { title: '概览', activeMenu: '/overview' }
  //   },
  //   {
  //     path: 'blockInfo',
  //     name: 'blockInfo',
  //     component: () => import('@/views/blockInfo'),
  //     meta: { title: '区块信息', activeMenu: '/overview' }
  //   },
  //   {
  //     path: 'tradeInfo',
  //     name: 'tradeInfo',
  //     component: () => import('@/views/tradeInfo'),
  //     meta: { title: '交易信息', activeMenu: '/overview' }
  //   }]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   children: [{
  //     path: 'node',
  //     name: 'node',
  //     component: () => import('@/views/node'),
  //     meta: { title: '节点管理', activeMenu: '/node' }
  //   }]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   children: [{
  //     path: 'privateKey',
  //     name: 'privateKey',
  //     component: () => import('@/views/privatekey'),
  //     meta: { title: '私钥管理', activeMenu: '/privateKey' }
  //   }]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/report',
  //   children: [{
  //     path: 'report',
  //     name: 'report',
  //     component: () => import('@/views/report'),
  //     meta: { title: '评价报告', activeMenu: '/report' }
  //   }]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   children: [{
  //     path: 'material',
  //     name: 'material',
  //     component: () => import('@/views/material'),
  //     meta: { title: '资料中心', activeMenu: '/material' }
  //   }]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   children: [{
  //     path: 'account',
  //     name: 'account',
  //     component: () => import('@/views/account'),
  //     meta: { title: '账号管理', activeMenu: '/account' }
  //   }]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   children: [{
  //     path: 'role',
  //     name: 'role',
  //     component: () => import('@/views/role'),
  //     meta: { title: '角色管理', activeMenu: '/role' }
  //   }]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   children: [{
  //     path: 'router',
  //     name: 'router',
  //     component: () => import('@/views/menu'),
  //     meta: { title: '菜单管理', activeMenu: '/router' }
  //   }]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'exercise',
  //       name: 'exercise',
  //       component: () => import('@/views/exercise/contract'),
  //       meta: { title: '实操练习', icon: '' }
  //     }
  //   ]
  // }

  // -------------------------
  {
    path: '/',
    redirect: '/overview',
    component: Layout,
    meta: { title: '区块信息', activeMenu: '/overview' },
    hidden: true,
    children: [
      {
        path: 'block-info',
        name: 'blockInfo',
        component: () => import('@/views/blockinfo'),
        meta: { title: '区块信息', activeMenu: '/overview' }
      },
      {
        path: 'trade-info',
        name: 'tradeInfo',
        component: () => import('@/views/tradeinfo'),
        meta: { title: '交易信息', activeMenu: '/overview' }
      }]
  }
  // {
  //   path: '/',
  //   component: Layout,
  //   children: [{
  //     path: 'node',
  //     name: 'node',
  //     component: () => import('@/views/node'),
  //     meta: { title: '节点管理', activeMenu: '/node' }
  //   }]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   children: [{
  //     path: 'privateKey',
  //     name: 'privateKey',
  //     component: () => import('@/views/privateKey'),
  //     meta: { title: '私钥管理', activeMenu: '/privateKey' }
  //   }]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/report',
  //   children: [{
  //     path: 'report',
  //     name: 'report',
  //     component: () => import('@/views/report'),
  //     meta: { title: '评价报告', activeMenu: '/report' }
  //   }]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   children: [{
  //     path: 'material',
  //     name: 'material',
  //     component: () => import('@/views/material'),
  //     meta: { title: '资料中心', activeMenu: '/material' }
  //   }]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   children: [{
  //     path: 'account',
  //     name: 'account',
  //     component: () => import('@/views/account'),
  //     meta: { title: '账号管理', activeMenu: '/account' }
  //   }]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   children: [{
  //     path: 'role',
  //     name: 'role',
  //     component: () => import('@/views/role'),
  //     meta: { title: '角色管理', activeMenu: '/role' }
  //   }]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   children: [{
  //     path: 'router',
  //     name: 'router',
  //     component: () => import('@/views/menu'),
  //     meta: { title: '菜单管理', activeMenu: '/router' }
  //   }]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'exercise',
  //       name: 'exercise',
  //       component: () => import('@/views/exercise/contract'),
  //       meta: { title: '实操练习', icon: '' }
  //     }
  //   ]
  // }
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/report',
  //   children: [{
  //     path: 'report',
  //     name: 'report',
  //     redirect: '/report/list',
  //     component: () => import('@/views/report/index'),
  //     meta: { title: '评价报告', activeMenu: '/report' },
  //     children: [{
  //       path: 'list',
  //       name: 'reportList',
  //       component: () => import('@/views/report/dataTable'),
  //       meta: { title: '评价报告', activeMenu: '/report' }
  //     }, {
  //       path: 'check',
  //       name: 'reportCheck',
  //       component: () => import('@/views/report/check'),
  //       meta: { title: '报告详情', activeMenu: '/report' }
  //     }]
  //   }]
  // }

  // {
  //   path: '/',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'review',
  //       name: 'review',
  //       component: () => import('@/views/review/index'),
  //       meta: { title: '审核', icon: 'shenhe' }
  //     }
  //   ]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'collection',
  //       name: 'collection',
  //       component: () => import('@/views/collection/index'),
  //       meta: { title: '归集', icon: 'guiji' }
  //     },
  //     {
  //       path: 'collection/record',
  //       name: 'collection-record',
  //       component: () => import('@/views/collection/record'),
  //       meta: { title: '概览', icon: 'gailan', activeMenu: '/collection' },
  //       hidden: true
  //     }
  //   ]
  // },

  // {
  //   path: '/',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'financial-statistics',
  //       name: 'financialStatistics',
  //       component: () => import('@/views/financialStatistics/index'),
  //       meta: { title: '财务统计', icon: 'caiwutongji' }
  //     }
  //   ]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'basic-settings',
  //       name: 'basicSettings',
  //       component: () => import('@/views/basicSettings/index'),
  //       meta: { title: '基础设置', icon: 'jichushezhi' }
  //     }
  //   ]
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'push-management',
  //       name: 'pushManagement',
  //       component: () => import('@/views/pushManagement/index'),
  //       meta: { title: '推送管理', icon: 'tuisongguanli' }
  //     }
  //   ]
  // }

  // ===业务代码结束===

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const routerContext = require.context('./', true, /\.js$/)
routerContext.keys().forEach(route => {
  // 如果是根目录的 index.js 、不处理
  if (route.startsWith('./index')) {
    return
  }
  const routerModule = routerContext(route)
  /**
   * 兼容 import export 和 require module.export 两种规范
   */
  routes = routes.concat(routerModule.default || routerModule)
})

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: routes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
